home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / ctlview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  9.2 KB  |  361 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFXCTL_CORE2_SEG
  14. #pragma code_seg(AFXCTL_CORE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // COleControl overridables for IViewObject implementation
  26.  
  27. BOOL COleControl::OnGetColorSet(DVTARGETDEVICE*, HDC, LPLOGPALETTE*)
  28. {
  29.     // Can be overridden by subclass
  30.     return FALSE;
  31. }
  32.  
  33. BOOL COleControl::OnGetViewExtent(DWORD dwDrawAspect, LONG /* lindex */,
  34.     DVTARGETDEVICE* /* ptd */, LPSIZEL lpsizel)
  35. {
  36.     // Can be overridden by subclass for two-pass drawing
  37.     if (dwDrawAspect == DVASPECT_OPAQUE || dwDrawAspect == DVASPECT_TRANSPARENT)
  38.         dwDrawAspect = DVASPECT_CONTENT;
  39.     return SUCCEEDED(m_xOleObject.GetExtent(dwDrawAspect, lpsizel));
  40. }
  41.  
  42. BOOL COleControl::OnGetViewRect(DWORD dwAspect, LPRECTL pRect)
  43. {
  44.     // Can be overridden by subclass for two-pass drawing
  45.     SIZEL size;
  46.     OnGetViewExtent(dwAspect, -1, NULL, &size);
  47.     pRect->left = 0;
  48.     pRect->top = 0;
  49.     pRect->right = size.cx;
  50.     pRect->bottom = -size.cy;
  51.     return TRUE;
  52. }
  53.  
  54. DWORD COleControl::OnGetViewStatus()
  55. {
  56.     // Can be overridden by subclass for two-pass drawing
  57.     return VIEWSTATUS_OPAQUE;
  58. }
  59.  
  60. BOOL COleControl::OnQueryHitPoint(DWORD dwAspect, LPCRECT /* pRectBounds */,
  61.     POINT /* ptlLoc */, LONG /* lCloseHint */, DWORD* pHitResult)
  62. {
  63.     // Can be overridden by subclass for non-rectangular hit-testing
  64.     if (dwAspect == DVASPECT_CONTENT)
  65.     {
  66.         *pHitResult = HITRESULT_HIT;
  67.         return TRUE;
  68.     }
  69.     else
  70.     {
  71.         return FALSE;
  72.     }
  73. }
  74.  
  75. BOOL COleControl::OnQueryHitRect(DWORD dwAspect, LPCRECT /* pRectBounds */,
  76.     LPCRECT /* prcLoc */, LONG /* lCloseHint */, DWORD* pHitResult)
  77. {
  78.     // Can be overridden by subclass for non-rectangular hit-testing
  79.     if (dwAspect == DVASPECT_CONTENT)
  80.     {
  81.         *pHitResult = HITRESULT_HIT;
  82.         return TRUE;
  83.     }
  84.     else
  85.     {
  86.         return FALSE;
  87.     }
  88. }
  89.  
  90. BOOL COleControl::OnGetNaturalExtent(DWORD /* dwAspect */, LONG /* lindex */,
  91.     DVTARGETDEVICE* /* ptd */, HDC /* hicTargetDev */,
  92.     DVEXTENTINFO* /* pExtentInfo */, LPSIZEL /* psizel */)
  93. {
  94.     // Can be overridden by subclass to provide sizing hints
  95.     return FALSE;
  96. }
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // COleControl::XViewObject
  100.  
  101. STDMETHODIMP_(ULONG) COleControl::XViewObject::AddRef()
  102. {
  103.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  104.     return (ULONG)pThis->ExternalAddRef();
  105. }
  106.  
  107. STDMETHODIMP_(ULONG) COleControl::XViewObject::Release()
  108. {
  109.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  110.     return (ULONG)pThis->ExternalRelease();
  111. }
  112.  
  113. STDMETHODIMP COleControl::XViewObject::QueryInterface(
  114.     REFIID iid, LPVOID* ppvObj)
  115. {
  116.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  117.     return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  118. }
  119.  
  120.  
  121. STDMETHODIMP COleControl::XViewObject::Draw(DWORD dwDrawAspect, LONG lindex,
  122.     void* pvAspect, DVTARGETDEVICE* ptd, HDC hicTargetDev, HDC hdcDraw,
  123.     LPCRECTL lprcBounds, LPCRECTL lprcWBounds,
  124.     BOOL (CALLBACK* pfnContinue)(DWORD), DWORD dwContinue)
  125. {
  126.     METHOD_PROLOGUE_EX(COleControl, ViewObject)
  127.  
  128.     HRESULT hResult = S_OK;
  129.  
  130.     CRect rc;
  131.  
  132.     if (lprcBounds == NULL)
  133.     {
  134.         if (pThis->m_bInPlaceSiteWndless)
  135.             rc.CopyRect(pThis->m_rcPos);
  136.         else
  137.             return E_INVALIDARG;
  138.     }
  139.     else
  140.     {
  141.         rc.SetRect((int)lprcBounds->left, (int)lprcBounds->top,
  142.             (int)lprcBounds->right, (int)lprcBounds->bottom);
  143.     }
  144.  
  145.     // Check if optimized drawing is permitted
  146.     if (pvAspect != NULL && (pThis->GetControlFlags() & canOptimizeDraw))
  147.     {
  148.         pThis->m_bOptimizedDraw = (((DVASPECTINFO*)pvAspect)->dwFlags &
  149.             DVASPECTINFOFLAG_CANOPTIMIZE);
  150.     }
  151.  
  152.     AfxLockTempMaps();
  153.  
  154.     // Convert from rectangle from logical to device coordinates,
  155.     // save DC state, and switch to MM_TEXT mode.  After drawing,
  156.     // restore DC state.
  157.  
  158.     switch (dwDrawAspect)
  159.     {
  160.     case DVASPECT_CONTENT:
  161. #if !defined(_WIN32_WCE)
  162.         if (GetDeviceCaps(hdcDraw, TECHNOLOGY) == DT_METAFILE)
  163.         {
  164.             // If attributes DC is NULL, create one, based on ptd.
  165.             HDC hAttribDC = hicTargetDev;
  166.             if (hicTargetDev == NULL)
  167.                 hAttribDC = ::_AfxOleCreateDC(ptd);
  168.  
  169.             // Draw into the metafile DC.
  170.             CMetaFileDC dc;
  171.             dc.Attach(hdcDraw);
  172.             dc.SetAttribDC(hAttribDC);
  173.  
  174.             pThis->DrawMetafile(&dc, rc);
  175.  
  176.             dc.SetAttribDC(NULL);
  177.             dc.Detach();
  178.  
  179.             // If we created an attributes DC, delete it now.
  180.             if (hicTargetDev == NULL)
  181.                 ::DeleteDC(hAttribDC);
  182.         }
  183.         else
  184. #endif // _WIN32_WCE
  185.         {
  186.             CDC* pDC = CDC::FromHandle(hdcDraw);
  187.             pThis->DrawContent(pDC, rc);
  188.         }
  189.         break;
  190.  
  191. #if !defined(_WIN32_WCE)
  192.     default:
  193.         if (pThis->m_pDefIViewObject == NULL)
  194.             pThis->m_pDefIViewObject =
  195.                 (LPVIEWOBJECT)pThis->QueryDefHandler(IID_IViewObject);
  196.  
  197.         if (pThis->m_pDefIViewObject != NULL)
  198.         {
  199.             hResult = pThis->m_pDefIViewObject->Draw(
  200.                 dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, hdcDraw,
  201.                 lprcBounds, lprcWBounds, pfnContinue, dwContinue);
  202.         }
  203. #endif // _WIN32_WCE
  204.     }
  205.  
  206.     AfxUnlockTempMaps();
  207.     pThis->m_bOptimizedDraw = FALSE;
  208.     return hResult;
  209. }
  210.  
  211. STDMETHODIMP COleControl::XViewObject::GetColorSet(DWORD dwDrawAspect,
  212.     LONG lindex, void*, DVTARGETDEVICE* ptd, HDC hicTargetDev,
  213.     LPLOGPALETTE* ppColorSet)
  214. {
  215.     METHOD_PROLOGUE_EX(COleControl, ViewObject)
  216.  
  217.     HRESULT hr = E_FAIL;
  218.  
  219.     if ((dwDrawAspect == DVASPECT_CONTENT) && (lindex == -1) &&
  220.         pThis->OnGetColorSet(ptd, hicTargetDev, ppColorSet))
  221.     {
  222.         hr = S_OK;
  223.     }
  224.  
  225.     return hr;
  226. }
  227.  
  228. STDMETHODIMP COleControl::XViewObject::Freeze(DWORD, LONG, void*, DWORD*)
  229. {
  230.     return E_NOTIMPL;
  231. }
  232.  
  233. STDMETHODIMP COleControl::XViewObject::Unfreeze(DWORD)
  234. {
  235.     return E_NOTIMPL;
  236. }
  237.  
  238. STDMETHODIMP COleControl::XViewObject::SetAdvise(DWORD aspects, DWORD advf,
  239.                     LPADVISESINK pAdvSink)
  240. {
  241.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  242.  
  243.     _AFXCTL_ADVISE_INFO** ppAdviseInfo = &pThis->m_pAdviseInfo;
  244.  
  245.     // Allocate space for advise info, if necessary.
  246.     if (*ppAdviseInfo == NULL)
  247.     {
  248.         TRY
  249.             *ppAdviseInfo = new _AFXCTL_ADVISE_INFO;
  250.         END_TRY
  251.  
  252.         if (*ppAdviseInfo == NULL)
  253.             return E_OUTOFMEMORY;
  254.     }
  255.  
  256.     _AFXCTL_ADVISE_INFO* pAdviseInfo = *ppAdviseInfo;
  257.  
  258.     // Release previous sink, if any.
  259.     if (pAdviseInfo->m_pAdvSink != NULL)
  260.         pAdviseInfo->m_pAdvSink->Release();
  261.  
  262.     // Store new advise info.
  263.     pAdviseInfo->m_dwAspects = aspects;
  264.     pAdviseInfo->m_dwAdvf = advf;
  265.     pAdviseInfo->m_pAdvSink = pAdvSink;
  266.     if (pAdvSink != NULL)
  267.         pAdvSink->AddRef();
  268.  
  269.     return S_OK;
  270. }
  271.  
  272. STDMETHODIMP COleControl::XViewObject::GetAdvise(DWORD* pAspects, DWORD* pAdvf,
  273.     LPADVISESINK* ppAdvSink)
  274. {
  275.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  276.  
  277.     _AFXCTL_ADVISE_INFO* pAdviseInfo = pThis->m_pAdviseInfo;
  278.  
  279.     if ((pAdviseInfo != NULL) && (pAdviseInfo->m_pAdvSink != NULL))
  280.     {
  281.         if (pAspects != NULL)
  282.             *pAspects = pAdviseInfo->m_dwAspects;
  283.  
  284.         if (pAdvf != NULL)
  285.             *pAdvf = pAdviseInfo->m_dwAdvf;
  286.  
  287.         if (ppAdvSink != NULL)
  288.         {
  289.             *ppAdvSink = pAdviseInfo->m_pAdvSink;
  290.             if (*ppAdvSink != NULL)
  291.                 (*ppAdvSink)->AddRef();
  292.         }
  293.     }
  294.     else
  295.     {
  296.         if (pAspects != NULL)
  297.             *pAspects = 0;
  298.  
  299.         if (pAdvf != NULL)
  300.             *pAdvf = 0;
  301.  
  302.         if (ppAdvSink != NULL)
  303.             *ppAdvSink = NULL;
  304.     }
  305.  
  306.     return S_OK;
  307. }
  308.  
  309. STDMETHODIMP COleControl::XViewObject::GetExtent(DWORD dwDrawAspect,
  310.     LONG lindex, DVTARGETDEVICE* ptd, LPSIZEL lpsizel)
  311. {
  312.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  313.     return pThis->OnGetViewExtent(dwDrawAspect, lindex, ptd, lpsizel) ? S_OK :
  314.         E_FAIL;
  315. }
  316.  
  317. STDMETHODIMP COleControl::XViewObject::GetRect(DWORD dwAspect, LPRECTL pRect)
  318. {
  319.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  320.     return pThis->OnGetViewRect(dwAspect, pRect) ? S_OK : DV_E_DVASPECT;
  321. }
  322.  
  323. STDMETHODIMP COleControl::XViewObject::GetViewStatus(DWORD* pdwStatus)
  324. {
  325.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  326.     *pdwStatus = pThis->OnGetViewStatus();
  327.     return S_OK;
  328. }
  329.  
  330. STDMETHODIMP COleControl::XViewObject::QueryHitPoint(DWORD dwAspect,
  331.     LPCRECT pRectBounds, POINT ptlLoc, LONG lCloseHint, DWORD* pHitResult)
  332. {
  333.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  334.     return pThis->OnQueryHitPoint(dwAspect, pRectBounds, ptlLoc, lCloseHint,
  335.         pHitResult) ? S_OK : E_FAIL;
  336. }
  337.  
  338. STDMETHODIMP COleControl::XViewObject::QueryHitRect(DWORD dwAspect,
  339.     LPCRECT pRectBounds, LPCRECT prcLoc, LONG lCloseHint, DWORD* pHitResult)
  340. {
  341.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  342.     return pThis->OnQueryHitRect(dwAspect, pRectBounds, prcLoc, lCloseHint,
  343.         pHitResult) ? S_OK : E_FAIL;
  344. }
  345.  
  346. STDMETHODIMP COleControl::XViewObject::GetNaturalExtent(DWORD dwAspect,
  347.     LONG lindex, DVTARGETDEVICE* ptd, HDC hicTargetDev,
  348.     DVEXTENTINFO* pExtentInfo, LPSIZEL psizel)
  349. {
  350.     METHOD_PROLOGUE_EX_(COleControl, ViewObject)
  351.     return pThis->OnGetNaturalExtent(dwAspect, lindex, ptd, hicTargetDev,
  352.         pExtentInfo, psizel) ? S_OK : E_NOTIMPL;
  353. }
  354.  
  355. /////////////////////////////////////////////////////////////////////////////
  356. // Force any extra compiler-generated code into AFX_INIT_SEG
  357.  
  358. #ifdef AFX_INIT_SEG
  359. #pragma code_seg(AFX_INIT_SEG)
  360. #endif
  361.